﻿using Ledict.Core.Data;
using Ledict.Utility.Common;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    /// <summary>
    /// 操作日志
    /// 2017年5月22日，ljj添加
    /// </summary>
    public class OperLogDAL
    {
        private static string DbName = "JudgeDoc";
        //private static string CommonDbName = "LdtCommonManage";

        public static bool AddOperLog(string username,string oper_Type,string oper_Table,string strWhere)
        {
            string guid = Guid.NewGuid().ToString();
            string datetime = DateTime.Now.ToString();

            string insertSql = String.Format(@"insert into SYS_OperLog(Oper_Id, Oper_Ip, Oper_Type, Oper_Table, Oper_Time)
                                               values('{0}','{1}','{2}','{3}','{4}')",
                                               guid, username, oper_Type, oper_Table + " " + Other.GetLocalIP() + strWhere, datetime);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(insertSql);
            //oBase.ExecuteNonQuery(oCmd);

            //string databak = String.Format(@"insert into SYS_OperLog_{0}
            //                                 select '{1}',* from {0} where {2}",
            //                                 oper_Table, guid, strWhere);
            //oCmd = oBase.GetSqlStringCommand(databak);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }
    }
}
